﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NETCORE.SqlSugar.Model;
using NETCORE.SqlSugar.Service;
using SqlSugar;

namespace NETCORE.SqlSugar.Controllers
{

    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private SqlSugarClient DB;

        public TestController(ISqlSugarBase sugarBase)
        {
            this.DB = sugarBase.GetDB();
        }

        [HttpGet]
        [Route("Get1")]
        public ActionResult<string> Get1()
        {

            ///*查询*/
            var list = DB.Queryable<T_Mores>().ToList();//查询所有
            
            var getById = DB.Queryable<T_Mores>().InSingle(new Guid("B7455E7D-4801-4F5C-AD5A-4BB548996C07"));//根据主键查询
            
            //var getByWhere = db.Queryable<StudentModel>().Where(it => it.Id == 1).ToList();//根据条件查询
            //var total = 0;
            //var getPage = db.Queryable<StudentModel>().Where(it => it.Id == 1).ToPageList(1, 2, ref total);//根据分页查询
            //                                                                                               //多表查询用法 http://www.codeisbug.com/Doc/8/1124

            ///*插入*/
            //var data = new Student() { Name = "jack" };
            //db.Insertable(data).ExecuteCommand();
            ////更多插入用法 http://www.codeisbug.com/Doc/8/1130

            ///*更新*/
            //var data2 = new Student() { Id = 1, Name = "jack" };
            //db.Updateable(data2).ExecuteCommand();
            ////更多更新用法 http://www.codeisbug.com/Doc/8/1129

            ///*删除*/
            //db.Deleteable<StudentModel>(1).ExecuteCommand();
            ////更多删除用法 http://www.codeisbug.com/Doc/8/1128
            ///
            return Ok("ddd");
        }

    }
}
